import 'package:flutter/material.dart';
import 'package:flutterapp/config.dart';
import 'package:flutterapp/models/room_list_item_data.dart';

import 'common_tag.dart';

class RoomListItemWidget extends StatelessWidget {
  final RoomListItemData data;

  const RoomListItemWidget(
    this.data, {
    Key key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    var imageUrl = data.imageUri.startsWith('http')
        ? data.imageUri
        : Config.QN + data.imageUri;
    return GestureDetector(
      behavior: HitTestBehavior.opaque,
      onTap: () {
        Navigator.of(context).pushNamed('roomDetail/${data.id}');
      },
      child: Container(
        padding: EdgeInsets.only(left: 10.0, right: 10.0, bottom: 10.0),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: [
            Padding(
              padding: EdgeInsets.only(left: 10.0),
            ),
            Image.network(
              imageUrl,
              width: 150.0,
              height: 100.0,
            ),
            Padding(
              padding: EdgeInsets.only(left: 20.0),
            ),
            Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    data.title,
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                    style: TextStyle(fontWeight: FontWeight.w600),
                  ),
                  Text(
                    data.subTitle,
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                    style: TextStyle(fontWeight: FontWeight.w600),
                  ),
                  Wrap(
                    children: data.tags.map((e) => CommonTag(e)).toList(),
                  ),
                  Text(
                    '${data.price} 元/月',
                    style: TextStyle(
                        color: Colors.orange,
                        fontSize: 16.0,
                        fontWeight: FontWeight.w600),
                  ),
                  // Container(
                  //   child: Text('为342'),
                  // )
                ],
              ),
            )
          ],
        ),
      ),
    );
  }
}

//docker run -itd --name mysql-test -p 3308:3306 -e MYSQL_ROOT_PASSWORD=gbj123 mysql
//CREATE USER 'gubanjie'@'%' IDENTIFIED WITH mysql_native_password BY 'gubanjie';

//docker run --name mysql -p 3308:3306 -e MYSQL_ROOT_PASSWORD=gubanjie -d mysql

// docker exec -it f884bab1982b bash

//GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';

// CREATE USER 'gubanjie'@'%' IDENTIFIED WITH mysql_native_password BY 'gubanjie';

//docker run --name mysql -p 3308:3306 -e MYSQL_ROOT_PASSWORD=gubanjie -d mysql
//将刚创建的用户授权到root
//GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';
